﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LevelInfoForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.BasicDataManage.LevelInfoForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" method="post">
    <input name="LvID" class="mini-hidden" />
    <fieldset style="border: solid 1px #aaa; padding: 5px;">
        <legend>层级信息</legend>
        <div style="padding-left: 11px; padding-bottom: 5px;">
            <table style="table-layout: fixed;">
                <tr>
                    <td style="width: 70px;">
                        产线：
                    </td>
                    <td style="width: 300px;">
                        <div id="LineID" name="LineID" class="mini-combobox" style="width: 300px;" popupwidth="300"
                            required="true" onvaluechanged="onLineIDChanged" textfield="LineName" valuefield="LineID"
                            url="../Service/BasicDataManageHandler.ashx?action=GetLineListByCombobox">
                            <div property="columns">
                                <div header="产线编号" field="LineCode">
                                </div>
                                <div header="产线名称" field="LineName">
                                </div>
                            </div>
                        </div>
                    </td>
                    <td style="width: 70px;">
                        异常原因：
                    </td>
                    <td style="width: 300px;">
                        <div id="ETypeCode" name="ETypeCode" class="mini-combobox" style="width: 300px;"
                            required="true" onvaluechanged="onETypeCodeChanged" popupwidth="300" textfield="ETypeName"
                            valuefield="ETypeCode" url="../Service/BasicDataManageHandler.ashx?action=GetETypeListByCombobox">
                            <div property="columns">
                                <div header="异常原因编号" field="ETypeCode">
                                </div>
                                <div header="异常原因名称" field="ETypeName">
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="width: 70px;">
                        状态：
                    </td>
                    <td style="width: 300px;">
                        <select id="TimeoutStatus" name="TimeoutStatus" onvaluechanged="onTimeoutStatusChanged"
                            class="mini-radiobuttonlist">
                            <option value="0">处理超时</option>
                            <option value="1">签到超时</option>
                        </select>
                    </td>
                    <td style="width: 80px;">
                        超时时间：
                    </td>
                    <td style="width: 300px;">
                        <input name="MsgTimeOut" class="mini-spinner" required="true" style="width: 250px;"
                            maxvalue="10000" minvalue="1" vtype="int" />(分钟)
                    </td>
                </tr>
                <tr>
                    <td style="width: 70px;">
                        层次：
                    </td>
                    <td style="width: 300px;">
                        <input name="LevelIdx" id="LevelIdx" class="mini-textbox" style="width: 300px;" required="true" />
                    </td>
                    <td style="width: 80px;">
                    </td>
                    <td style="width: 300px;">
                    </td>
                </tr>
            </table>
        </div>
    </fieldset>
    <fieldset style="border: solid 1px #aaa; padding: 5px; height: 300px;">
        <legend>人员信息</legend>
        <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
            <table style="width: 100%;">
                <tr>
                    <td style="width: 100%;">
                        <a class="mini-button" iconcls="icon-add" onclick="add();" plain="true">添加</a> <a
                            class="mini-button" iconcls="icon-remove" onclick="removeRow()" plain="true">删除</a>
                    </td>
                </tr>
            </table>
        </div>
        <!--撑满页面-->
        <div class="mini-fit">
            <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="RowID"
                showfooter="false" multiselect="true">
                <div property="columns">
                    <div type="checkcolumn">
                    </div>
                    <div field="LoginCode" width="120" headeralign="center" allowsort="false">
                        登录账号
                    </div>
                    <div field="FullName" width="140" headeralign="center" allowsort="false">
                        姓名
                    </div>
                    <div field="MobileNo" width="120" headeralign="center" allowsort="false">
                        手机号码
                    </div>
                    <div field="DptName" width="100" headeralign="center" allowsort="false">
                        部门
                    </div>
                </div>
            </div>
        </div>
    </fieldset>
    <div style="text-align: center; padding: 10px;">
        <a class="mini-button" iconcls="icon-save" onclick="onOk" style="width: 60px; margin-right: 20px;">
            保存</a> <a class="mini-button" iconcls="icon-cancel" onclick="onCancel" style="width: 60px;">
                取消</a>
    </div>
    </form>
    <script type="text/javascript">
        mini.parse();
        mini.getbyName("TimeoutStatus").setValue("0");
        var grid = mini.get("datagrid1");
        var form = new mini.Form("form1");
        var viewaction;
        function SaveData() {
            var data = grid.getData();
            var o = form.getData();
            form.validate();
            if (form.isValid() == false) return;
            if (data.length <= 0) {
                mini.confirm("汇报层级没有添加人员信息是否继续保存？", "确定？",
                    function (action) {
                        if (action == "ok") {
                            saveData(o, data);
                        } else {
                            return false;
                        }
                    });
            }
            else {
                saveData(o, data);
            }
        }

        function saveData(o, data) {
            o.arrList = data;
            var json = mini.encode([o]);
            if (viewaction == "edit") {
                $.ajax({
                    url: "../Service/BasicDataManageHandler.ashx?action=ModifyLevel",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
            else {
                $.ajax({
                    url: "../Service/BasicDataManageHandler.ashx?action=AddLevel",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
        }

        ////////////////////
        //标准方法接口定义
        function SetData(data) {
            var LevelIdx = mini.get("LevelIdx");
            LevelIdx.setEnabled(false);
            if (data.action == "edit") {
                viewaction = data.action;
                var LineID = mini.get("LineID");
                LineID.setEnabled(false);
                var ETypeCode = mini.get("ETypeCode");
                ETypeCode.setEnabled(false);
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                viewaction = data.action;
                $.ajax({
                    url: "../service/BasicDataManageHandler.ashx?action=GetLevelInfo&LvID=" + data.LvID,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        form.setChanged(false);
                        $.ajax({
                            url: "../service/BasicDataManageHandler.ashx?action=GetLevelDetailListByLvInfo&LvID=" + o.LvID + "&LevelIdx=" + o.LevelIdx,
                            cache: false,
                            success: function (text) {
                                var o = mini.decode(text);
                                grid.setData(o);
                                grid.load();
                            }
                        });
                    }
                });
            }
        }

        function GetData() {
            var o = form.getData();
            return o;
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }

        function onOk() {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }

        function add() {
            mini.open({
                url: "CommForm/SelectUserGridForm.aspx",
                title: "人员信息", width: 800, height: 495,
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);    //必须
                        if (data) {
                            var idMaps = {};
                            var datas = grid.getData();
                            for (var i = 0, l = datas.length; i < l; i++) {
                                var o = datas[i];
                                var id = o["UserID"];
                                idMaps[id] = o;
                            }
                            if (datas.length > 0) {
                                for (var i = data.length - 1; i >= 0; i--) {
                                    var o = data[i];
                                    var id = o["UserID"];
                                    if (idMaps[id] != null) data.removeAt(i);
                                }
                            }
                            grid.addRows(data);
                        }
                    }
                }
            });
        }

        function onETypeCodeChanged(e) {
            var LineID = mini.get("LineID").getValue();
            var TimeoutStatus = mini.get("TimeoutStatus").getValue();
            if (LineID) {
                LoadMaxLevelIdx(LineID, e.value, TimeoutStatus);
            }
        }
        function onLineIDChanged(e) {
            var ETypeCode = mini.get("ETypeCode").getValue();
            var TimeoutStatus = mini.get("TimeoutStatus").getValue();
            if (ETypeCode) {
                LoadMaxLevelIdx(e.value, ETypeCode, TimeoutStatus);
            }
        }

        function onTimeoutStatusChanged(e) {
            var LineID = mini.get("LineID").getValue();
            var ETypeCode = mini.get("ETypeCode").getValue();
            if (ETypeCode) {
                if (LineID) {
                    LoadMaxLevelIdx(LineID, ETypeCode, e.value);
                }
            }
        }

        function LoadMaxLevelIdx(LineID, ETypeCode, TimeoutStatus) {
            $.ajax({
                url: "../service/BasicDataManageHandler.ashx?action=GetMaxLevelIdx&LineID=" + LineID + "&ETypeCode=" + ETypeCode + "&TimeoutStatus=" + TimeoutStatus,
                cache: false,
                success: function (text) {
                    mini.get("LevelIdx").setValue(text);
                }
            });
        }

        function removeRow() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                grid.removeRows(rows, true);
            }
        }
    </script>
</body>
</html>
